﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using NUnit.Framework;
using CondominioG1.Persistencia.NHibernate;
using CondominioG1.Dominio;
using CondominioG1.Negocio;

using Spring.Context;
using Spring.Context.Support;

namespace CondominioG1.Pruebas.TestService
{

    [TestFixture]

    public class TestAreaService
    {

        private IApplicationContext Spring;

        [TestFixtureSetUp]
        public void InicializarPruebas()
        {
            //"assembly://assembly/namespace/capaPersistencia.xml",
            Spring = new XmlApplicationContext(
                "assembly://CondominioG1/CondominioG1/capaPersistencia.xml",
                "assembly://CondominioG1/CondominioG1/capaNegocio.xml"
                );

            // Obtengo una referencia a la clase de negocio a probar
            AreaService areaService = (AreaService)Spring.GetObject("areaService");
            ReservaService reservaService = (ReservaService)Spring.GetObject("reservaService");
            //Limpia la base de datos de Condominio
            reservaService.EliminarReservas();
            areaService.EliminarAreas();
            areaService.RegistrarArea("A0001", "Piscina", "A1", 30, "libre");
            areaService.RegistrarArea("A0002", "Gimnasio", "A1", 10, "libre");
            areaService.RegistrarArea("A0003", "Billar", "A1", 20, "reservada");
        }

        [Test]
        public void TestCrearArea()
        {
            AreaService areaService = (AreaService)Spring.GetObject("areaService");
            Assert.NotNull(areaService);
            Area area = null;
            Assert.DoesNotThrow(delegate {
                area = areaService.RegistrarArea("A004","Internet","B2",15,"libre");
            });
            Assert.NotNull(area);
        }
        
        [Test]
        public void Test_ModificarArea()
        {
            AreaService AreaService = (AreaService)Spring.GetObject("areaService");
            Area AreaModificado = null;
            Assert.DoesNotThrow(delegate {
                AreaModificado = AreaService.ModificarArea("A0002", "Gimnasio", "A1", 25, "reservada");
            });
            Assert.NotNull(AreaModificado);
        }

        [Test]
        public void Test_EliminarArea()
        {
            AreaService AreaService = (AreaService)Spring.GetObject("areaService");
            Area AreaEliminado = null;
            Assert.DoesNotThrow(delegate {
            AreaEliminado = AreaService.EliminarArea("A0003");
            });
        }

        [Test]
        public void TestListarAreaReservadas()
        {
            ICollection<Area> areasReservas = null;
            AreaService areaService = (AreaService)Spring.GetObject("areaService");
            Assert.DoesNotThrow(delegate
            {
                areasReservas = areaService.ListarReservaAreas("reservada");
            });

            Assert.IsNotNull(areasReservas);
            Assert.Greater(areasReservas.Count(), 0);
        }

        [Test]
        public void TestCrearArea_incorrectamente()
        {
            AreaService areaService = (AreaService)Spring.GetObject("areaService");
            Assert.NotNull(areaService);
            Area area = null;
            Assert.Catch<Exception>(delegate
            {
                area = areaService.RegistrarArea("A0002", "", "A1", 20, "reservada");
            });
        }
    }



}